﻿// -----------------------------------------------------------------------
// <copyright file="IMG_Slicing.cs" company="Hewlett-Packard">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace ImageProcessing.ImageProcessor
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class IMG_Slicing
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="IMG_Slicing"/> class.
        /// </summary>
        /// <param name="img_GreyBuffer">The img_ grey buffer.</param>
        public IMG_Slicing(Entities.IMG_Image img_GreyBuffer)
        {
            try
            {
                Entities.Pixel img_NewPixel;
                int width = img_GreyBuffer.Width;
                int height = img_GreyBuffer.Height;
                Entities.IMG_Image img_NewBuffer = new Entities.IMG_Image(width, height);
                this.Slice0 = new Entities.IMG_Image(width, height);
                this.Slice1 = new Entities.IMG_Image(width, height);
                this.Slice2 = new Entities.IMG_Image(width, height);
                this.Slice3 = new Entities.IMG_Image(width, height);
                this.Slice4 = new Entities.IMG_Image(width, height);
                this.Slice5 = new Entities.IMG_Image(width, height);
                this.Slice6 = new Entities.IMG_Image(width, height);
                this.Slice7 = new Entities.IMG_Image(width, height);
                for (int i = 0; i < height * width; i++)
                {
                    byte value = (byte)img_GreyBuffer.ImagePixels[i].Red;
                    byte newVal = 0;
                    newVal = (byte)(value & byte.Parse("1")) == byte.Parse("1") ? byte.Parse("255") : byte.Parse("0");
                    img_NewPixel = new Entities.Pixel(int.Parse(newVal.ToString()), int.Parse(newVal.ToString()), int.Parse(newVal.ToString()));
                    this.Slice0.ImagePixels[i] = img_NewPixel;
                    newVal = (byte)(value & byte.Parse("2")) == byte.Parse("2") ? byte.Parse("255") : byte.Parse("0");
                    img_NewPixel = new Entities.Pixel(int.Parse(newVal.ToString()), int.Parse(newVal.ToString()), int.Parse(newVal.ToString()));
                    this.Slice1.ImagePixels[i] = img_NewPixel;
                    newVal = (byte)(value & byte.Parse("4")) == byte.Parse("4") ? byte.Parse("255") : byte.Parse("0");
                    img_NewPixel = new Entities.Pixel(int.Parse(newVal.ToString()), int.Parse(newVal.ToString()), int.Parse(newVal.ToString()));
                    this.Slice2.ImagePixels[i] = img_NewPixel;
                    newVal = (byte)(value & byte.Parse("8")) == byte.Parse("8") ? byte.Parse("255") : byte.Parse("0");
                    img_NewPixel = new Entities.Pixel(int.Parse(newVal.ToString()), int.Parse(newVal.ToString()), int.Parse(newVal.ToString()));
                    this.Slice3.ImagePixels[i] = img_NewPixel;
                    newVal = (byte)(value & byte.Parse("16")) == byte.Parse("16") ? byte.Parse("255") : byte.Parse("0");
                    img_NewPixel = new Entities.Pixel(int.Parse(newVal.ToString()), int.Parse(newVal.ToString()), int.Parse(newVal.ToString()));
                    this.Slice4.ImagePixels[i] = img_NewPixel;
                    newVal = (byte)(value & byte.Parse("32")) == byte.Parse("32") ? byte.Parse("255") : byte.Parse("0");
                    img_NewPixel = new Entities.Pixel(int.Parse(newVal.ToString()), int.Parse(newVal.ToString()), int.Parse(newVal.ToString()));
                    this.Slice5.ImagePixels[i] = img_NewPixel;
                    newVal = (byte)(value & byte.Parse("64")) == byte.Parse("64") ? byte.Parse("255") : byte.Parse("0");
                    img_NewPixel = new Entities.Pixel(int.Parse(newVal.ToString()), int.Parse(newVal.ToString()), int.Parse(newVal.ToString()));
                    this.Slice6.ImagePixels[i] = img_NewPixel;
                    newVal = (byte)(value & byte.Parse("128")) == byte.Parse("128") ? byte.Parse("255") : byte.Parse("0");
                    img_NewPixel = new Entities.Pixel(int.Parse(newVal.ToString()), int.Parse(newVal.ToString()), int.Parse(newVal.ToString()));
                    this.Slice7.ImagePixels[i] = img_NewPixel;
                }
            }
            catch (Exception img_Ex)
            {
                Logger.LogException(img_Ex);
                throw;
            }
        }

        /// <summary>
        /// Gets or sets the slice0.
        /// </summary>
        /// <value>
        /// The slice0.
        /// </value>
        public Entities.IMG_Image Slice0 { get; set; }

        /// <summary>
        /// Gets or sets the slice1.
        /// </summary>
        /// <value>
        /// The slice1.
        /// </value>
        public Entities.IMG_Image Slice1 { get; set; }

        /// <summary>
        /// Gets or sets the slice2.
        /// </summary>
        /// <value>
        /// The slice2.
        /// </value>
        public Entities.IMG_Image Slice2 { get; set; }

        /// <summary>
        /// Gets or sets the slice3.
        /// </summary>
        /// <value>
        /// The slice3.
        /// </value>
        public Entities.IMG_Image Slice3 { get; set; }

        /// <summary>
        /// Gets or sets the slice4.
        /// </summary>
        /// <value>
        /// The slice4.
        /// </value>
        public Entities.IMG_Image Slice4 { get; set; }

        /// <summary>
        /// Gets or sets the slice5.
        /// </summary>
        /// <value>
        /// The slice5.
        /// </value>
        public Entities.IMG_Image Slice5 { get; set; }

        /// <summary>
        /// Gets or sets the slice6.
        /// </summary>
        /// <value>
        /// The slice6.
        /// </value>
        public Entities.IMG_Image Slice6 { get; set; }

        /// <summary>
        /// Gets or sets the slice7.
        /// </summary>
        /// <value>
        /// The slice7.
        /// </value>
        public Entities.IMG_Image Slice7 { get; set; }
    }
}
